package com.sxx.beautifulcity.adapter;

import android.content.Context;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.sxx.beautifulcity.R;

import java.util.List;

/**
 * Created by dllo on 15/10/30.
 * 天气背景
 */
public class BackGroundViewPagerAdapter extends PagerAdapter{

    private int[] images;



    public void addData(int[] images){
        this.images = images;
        notifyDataSetChanged();
    }


    @Override
    public int getCount() {
        return Integer.MAX_VALUE;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }
    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        LayoutInflater inflater = LayoutInflater.from(container.getContext());
        View v = inflater.inflate(R.layout.background_viewpahger_itme, null);
        ImageView image = (ImageView) v.findViewById(R.id.image);
        image.setBackgroundResource(images[position % (images.length)]);
        container.addView(v);
        return v;

    }
    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }
}
